from django.shortcuts import render, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
# Create your views here.
import json


@csrf_exempt
def ab_ajax(request):
    if request.method == 'POST':
        print(request.POST, type(request.POST), type(request.POST.get('i1')))
        i1 = request.POST.get('i1')
        i2 = request.POST.get('i2')
        i3 = int(i1) + int(i2)
        d = {'code': 100, 'msg': i3}
        # return JsonResponse(d)  # JsonResponse 返回的数据到了前端会自动反序列化成object，HttpResponse不会反序列化，是string类型
        return HttpResponse(json.dumps(d))  # JsonResponse 返回的数据到了前端会自动反序列化成object，HttpResponse不会反序列化，是string类型
    return render(request, 'index.html')